package com.example.demo.result;

import lombok.Getter;

@Getter
public class Result<T> {
    //状态码
    private Integer code;
    //提示信息
    private String msg;
    //泛型类型的数据
    private T data;

    private Result(Integer code) {
        this.code = code;
    }

    private Result(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(Integer code,String msg,T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResponseCode.SUCCESS.getCode());
    }
    public static <T> Result<T> success(String msg) {
        return new Result<>(ResponseCode.SUCCESS.getCode(),msg);
    }
    public static <T> Result<T> data(T data) {
        return new Result<>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMessage(),data);
    }

    public static <T> Result<T> fail(){
        return new Result<>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getMessage());
    }
    public static <T> Result<T> fail(String msg){
        return new Result<>(ResponseCode.ERROR.getCode(),msg);
    }
    public static <T> Result<T> fail(ResponseCode responseCode){
        return new Result<>(responseCode.getCode(),responseCode.getMessage());
    }
    public static <T> Result<T> fail(Integer code,String msg){
        return new Result<>(code, msg);
    }
}
